<template>
  <div class="pop-dialog-container">
    <div class="pop-dialog-main">
    <el-form label-position="right" :model="chargeForm" :label-width="formLabelWidth" disabled="disabled">
      <el-row>
        <el-col :span="11">
          <el-form-item label="楼栋名称">
            <el-input v-model="chargeForm.buildingName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="单元房号">
            <el-input v-model="chargeForm.roomNumber"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="11">
          <el-form-item label="收费类型">
            <el-select v-model="chargeForm.chargeType" placeholder="请选择收费类型">
              <el-option label="物业费" :value="10"></el-option>
              <el-option label="水费" :value="20"></el-option>
              <el-option label="电费" :value="30"></el-option>
              <el-option label="煤气费" :value="40"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="收费周期类型">
            <el-input v-model="chargeForm.billingCycle"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="11">
          <el-form-item label="收费周期开始时间">
            <el-input v-model="chargeForm.billingStartDate"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="收费周期结束时间">
            <el-input v-model="chargeForm.billingEndDate"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="11">
          <el-form-item label="金额">
            <el-input v-model="chargeForm.amount"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="滞纳金金额">
            <el-input v-model="chargeForm.lateFee"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="11">
          <el-form-item label="应付截止日期">
            <el-input v-model="chargeForm.dueDate"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="实际支付日期">
            <el-input v-model="chargeForm.paymentDate"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="11">
          <el-form-item label="支付状态">
            <el-select v-model="chargeForm.paymentStatus" placeholder="请选择支付状态">
              <el-option label="未支付" :value="10"></el-option>
              <el-option label="已支付" :value="20"></el-option>
              <el-option label="已作废" :value="90"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="创建时间">
            <el-input v-model="chargeForm.createTime"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="11">
          <el-form-item label="最后修改时间">
            <el-input v-model="chargeForm.modifyTime"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    </div>
    <div class="pop-dialog-footer">
      <el-row>
        <el-col :span="12" :offset="6">
          <div class="form-button-container">
            <el-button @click="onBack" type="primary">关闭</el-button>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script setup lang="ts">
import {defineEmits, defineProps, onMounted, reactive, ref, inject, toRefs} from 'vue';
import chargeApi from '@/api/chargeApi'
import type {Charge} from "@/types/resp/charge";
import type {Id} from "@/types/id"

const chargeForm = reactive<Partial<Charge>>({});
const props = defineProps<Id>()
const emit = defineEmits<{
  (e: 'closeChargeViewEvent'): void;
}>()
const formLabelWidth = ref<string>('')

onMounted(() => {
  initChargeById(props.id)
  const globalState = inject('globalState', {} as { formLabelWidth?: string })
  if (!globalState) {
    throw new Error('globalState is not provided');
  }
  const globalStateRefs = toRefs(globalState)
  if (globalStateRefs.formLabelWidth) {
    formLabelWidth.value = globalStateRefs.formLabelWidth.value || ''
  }
})

const initChargeById = async (id: number) => {
  const resp = await chargeApi.findById(id)
  if (resp && resp.code === 1 && resp.data) {
    Object.assign(chargeForm, resp.data)
  }
}
const onBack = () => {
  emit('closeChargeViewEvent')
}
</script>

<style lang="scss">
</style>